(function(window, path) {

	var ps = 6, psi = 0, r = 0, n = 0, d = function() {
		return window.jQuery && window.$ ? true : false
	}, l = function(element) {
		return document.getElementById(element)
	}, p = [ {
		url : "wro/basic.js",
		size : 700
	}, {
		url : "js/mango.js",
		size : 60,
		required : d,
		attachEvent : 10
	}, {
		url : "js/plugins.js",
		size : 50,
		required : d,
		order : 20
	}, {
		url : "js/script.js",
		size : 4,
		required : d,
		order : 30
	}, {
		url : "js/app.js",
		size : 3,
		required : d,
		order : 40
	}, {
		url : "js/login/login.js",
		size : 2,
		required : d,
		order : 50
	} ], setupLoadFile = function(files, i, loadingEvent) {
		var e = files[psi];
		if (e.required && !e.required()) {
			setTimeout(function() {
				setupLoadFile(e, i, loadingEvent, e.order || 20)
			}, e.order || 20);
			return;
		}

		var r = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
		var n = document.createElement(i == "js" ? "script" : "link");
		if (i == "js") {
			n.type = "text/javascript";
			n.src = e.url
		} else {
			n.type = "text/css";
			n.rel = "stylesheet";
			n.href = e.url
		}
		var s = function() {
			loadingEvent && loadingEvent(e);
			if (i == "js") {
				r.removeChild(n);
				psi++;
				if (psi < ps) {
					setupLoadFile(files, i, loadingEvent)
				}
			}
		};
		if (n.addEventListener) {
			n.addEventListener("load", s, false);
			n.addEventListener("error", s, false)
		} else if (n.attachEvent) {
			n.attachEvent("onreadystatechange", function() {
				if (n.readyState == "loaded" || n.readyState == "complete") {
					s()
				}
			})
		}
		r.appendChild(n)
	}, setupJs = function() {
		for ( var i = 0; i < p.length; i++) {
			r += p[i].size || 0;

		}
		setupLoadFile(p, "js", onLoadingFile);
	}, onLoadingFile = function(e) {
		n += e.size;
		var i = Math.floor(100 * n / r);
		processDo(i);

	}, setUpFinish = function() {
		var e = parseInt(o.style.width) || 0;
		var i = Math.min(100 * n / r + 10, 99);
		s = setInterval(function() {
			if (e >= i) {
				clearInterval(s)
			} else {
				j(++e)
			}
		}, 800)
	}, processDo = function(e) {
		if (s)
			clearInterval(s);
		var i = parseInt(o.style.width);
		s = setInterval(function() {
			if (i >= e) {
				clearInterval(s);
				if (e < 100) {
					setUpFinish();
				}
			} else {
				i += 5;
				j(Math.min(i, 99))
			}
		}, 20)
	}, j = function(e) {
		if (!a)
			return;
		o.style.width = a.innerText = e + "%"
	}, z = function() {
		var e = n;
		setTimeout(function() {
			if (n == r)
				return;
			if (e == n) {
				l("message1").innerText = "貌似网络不给力 -_-#";
				var i = setInterval(function() {
					if (n > e) {
						l("message1").innerText = "";
						clearInterval(i);
						z()
					}
				}, 300)
			} else {
				z()
			}
		}, 15 * 1e3)
	}, w = function() {
		var e = [ '<div id="loading-ui" style="width:400px;position:absolute;top:50%;left:50%;margin:-140px 0 0 -200px;">', '<div style="width:202px;margin:0 auto 40px;">', "</div>", '<div style="margin:20px auto;">', '<div style="height:22px;border:1px solid #aaa;background:#ddd;', "-webkit-border-radius:8px;-moz-border-radius:8px;border-radius:8px;", 'box-shadow: rgba(0, 0, 0, 0.2) 0px 1px 6px 0px;padding:1px 0;">', '<div style="width:396px;height:100%;">',
				'<div id="progress" style="width:0;height:100%;background:#2758B9;', "-webkit-border-radius:8px; -moz-border-radius:8px; border-radius:8px;", "background: -webkit-linear-gradient(top, #32C2E4, #2758B9);", "background: -ms-linear-gradient(top, #32C2E4, #2758B9);", "background: -moz-linear-gradient(top, #32C2E4, #2758B9);", "filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff32C2E4',endColorstr='#ff2758B9', GradientType=0);", '"></div>', "</div>", "</div>",
				'<div style="margin:8px auto 0;font-size:12px;color:#999;padding-left:8px;;position:relative;">', "<span>正在加载组件，请稍候...</span>", '<span id="progress-text" style="position:absolute;right:12px;">0%</span>', "</div>", "</div>", '<div id="message1" style="line-height:40px;text-align:center;font-size:13px;color:#666;">', "", "</div>", '<div id="message2" style="margin-top:30px;font-size:13px;color:#666;">', "", "</div>", "</div>" ].join("");
		document.body.innerHTML = document.body.innerHTML + e;
		o = l("progress");
		a = l("progress-text");
		setUpFinish()
	};
	window.onload = function() {
		w();
		setupJs();
		z();

	}
})(window);